<script lang="ts" setup>
import {
  bikeModifieldsDetailOrderTableCol,
  queryUserInfoDetailOrderRequestData,
  queryUserInfoDetailOrderTableCol
} from '@/api/user/types/user'
import UserInfoForm from '@/components/form/UserInfoForm.vue'
import { queryUserInfoDetailOrder } from '@/api/user'
import { useTable } from '@/hooks/useTable'
import { useRoute, useRouter } from 'vue-router'
import { defineAsyncComponent, reactive, onActivated } from 'vue'
import { getToken } from '@/utils/cache/cookies'
const BikeModifieldsTable = defineAsyncComponent(
  () => import('@/components/table/BikeModifieldsTable.vue')
)
const route = useRoute()
const router = useRouter()
const form = reactive<queryUserInfoDetailOrderRequestData>({
  phone: route.query.phone as string,
  orderId: route.query.orderId as string,
  type: '',
  selectType: 'bikeModified'
})
const handleFormSearch = () => {
  if (form.phone !== route.query.phone) {
    router.push({
      name: 'BikeModifieldsOrder',
      query: {
        phone: form.phone,
        orderId: form.orderId,
        type: form.type,
        selectType: 'bikemodifields'
      }
    })
    return
  }
  setCurrentPage(1)
  load()
}
const { pagination, handleSizeChange, handleCurrentChange, data, loading, setCurrentPage, load } =
  useTable<queryUserInfoDetailOrderTableCol>(queryUserInfoDetailOrder, getToken() ?? '', () => form)
defineExpose({ load })
onActivated(() => {
  form.phone = route.query.phone as string
  form.orderId = route.query.orderId as string
})
</script>

<template>
  <user-info-form v-model="form" type="bikemodifield" @search="handleFormSearch">
    <template #select>
      <el-form-item prop="type" label="订单状态">
        <el-select v-model="form.type" style="width: 150px">
          <el-option value="" label="不限" />
          <el-option value="1" label="待安装/待领取" />
          <el-option value="2" label="已安装/已领电" />
          <el-option value="3" label="已退单/已取消" />
        </el-select>
      </el-form-item>
    </template>
  </user-info-form>
  <bike-modifields-table :loading="loading" :data="data as bikeModifieldsDetailOrderTableCol[]" />
  <div flex justify-end mt-20>
    <el-pagination
      @current-change="handleCurrentChange"
      @size-change="handleSizeChange"
      v-model:current-page="pagination.pageNum"
      v-model:page-size="pagination.pageSize"
      background
      :total="pagination.total"
      layout="total,prev,pager,next,jumper,sizes"
    />
  </div>
</template>

<style scoped></style>
